/**
 * =========================== 通用网络请求方法 ===========================
 */

//加入下面的代码

/**跟文件名得到文件的图标*/

function getFileIcon(fileNameOrPath) {
	var suffix = getSuffix(fileNameOrPath);
	var icon = "";
	switch (suffix.trim().toLowerCase()) {
		case "doc":
		case "docx":
			icon = "images/ic_word_item.png";
			break;
		case "xls":
		case "xlsx":
			icon = "images/ic_excl_item.png";
			break;
		case "pdf":
			icon = "images/ic_pdf_item.png";
			break;
		case "ppt":
		case "pptx":
			icon = "images/ic_ppt_item.png";
			break;
		case "png":
		case "jpg":
		case "jpeg":
		case "bmp":
		case "tif":
		case "gif":
		case "PNG":
		case "JPG":
		case "JPEG":
		case "BMP":
		case "TIF":
		case "GIF":
			icon = "images/ic_image_item.png";
			break;
		case "rm":
		case "rmvb":
		case "wmv":
		case "avi":
		case "mp4":
		case "3gp":
		case "mkv":
		case "RM":
		case "RMVB":
		case "WMV":
		case "AVI":
		case "MP4":
		case "3GP":
		case "MKV":
			icon = "images/ic_video_item.png";
			break;
		case "rar":
		case "r":
		case "zip":
		case "z":
		case "cab":
		case "arj":
		case "lzh":
		case "ace":
		case "7-zip":
		case "tar":
		case "gzip":
		case "uue":
		case "bz2":
		case "jar":
		case "iso":
		case "RAR":
		case "R":
		case "ZIP":
		case "Z":
		case "CAB":
		case "ARJ":
		case "LZH":
		case "ACE":
		case "7-ZIP":
		case "TAR":
		case "GZIP":
		case "GZip":
		case "UUE":
		case "BZ2":
		case "JAR":
		case "ISO":
			icon = "images/ic_compress_item.png";
			break;
		default:
			icon = "images/ic_unknow.png";
			break;
	}
	return icon;
}

/**得到文件后缀*/
function getSuffix(fileNameOrPath) {
	var last_len = fileNameOrPath.lastIndexOf(".");
	var len = fileNameOrPath.length;
	var pathf = fileNameOrPath.substring(last_len + 1, len);
	return pathf;
}

function getFileSize(fileByte) {
	var fileSizeByte = fileByte;
	var fileSizeMsg = "";
	if (fileSizeByte < 1048576) fileSizeMsg = (fileSizeByte / 1024).toFixed(2) + "KB";
	else if (fileSizeByte == 1048576) fileSizeMsg = "1MB";
	else if (fileSizeByte > 1048576 && fileSizeByte < 1073741824) fileSizeMsg = (fileSizeByte / (1024 * 1024)).toFixed(2) +
		"MB";
	else if (fileSizeByte > 1048576 && fileSizeByte == 1073741824) fileSizeMsg = "1GB";
	else if (fileSizeByte > 1073741824 && fileSizeByte < 1099511627776) fileSizeMsg = (fileSizeByte / (1024 * 1024 *
			1024))
		.toFixed(2) + "GB";
	else fileSizeMsg = "文件超过1TB";
	return fileSizeMsg;
}

module.exports = {
	getSuffix: getSuffix
}
